package array;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 题目：在排序数组中查找元素的第一个和最后一个位置
 * 本题采用最直接的方式，时间复杂度为On^2
 * input:   [5,7,7,8,8,10]
 *           8
 * output:  [3,4]
 */
public class SearchRange {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.substring(1, s.length() - 1).split(",");

        int[] nums = new int[split.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(split[i]);
        }
        int target = sc.nextInt();
        System.out.println(Arrays.toString(searchRange(nums, target)));
        sc.close();
    }

    public static int[] searchRange(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            int left = i;
            int right = i;
            if (target == nums[i]) {
                while (right < nums.length && target == nums[right]) {
                    right++;
                }
                return new int[]{left, right - 1};
            }
        }
        return new int[]{-1, -1};
    }
}
